<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">
            <h:form>
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListCustomerAccountEntityEmpty}" rendered="#{customerAccountEntityController.assignedAccountItems.rowCount == 0}"/>
                <h:panelGroup rendered="#{customerAccountEntityController.assignedAccountItems.rowCount > 0}">
                    <p:dataTable value="#{customerAccountEntityController.assignedAccountItems}" var="item" style="table-layout:fixed" paginator="true" rows="10"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">
                        <p:column filterBy="#{item.id}" sortBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="Account ID"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>

                        <p:column filterBy="#{item.customer.fullname}" sortBy="#{item.customer.fullname}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerAccountEntityTitle_customer}"/>
                            </f:facet>
                            <h:outputText value="#{item.customer.fullname}"/>
                        </p:column>

                        <p:column filterBy="#{item.creditBalance}" sortBy="#{item.creditBalance}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerAccountEntityTitle_creditBalance}"/>
                            </f:facet>
                            <h:outputText value="#{item.creditBalance}"/>
                        </p:column>

                        <p:column filterBy="#{item.cashBalance}" sortBy="#{item.cashBalance}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerAccountEntityTitle_cashBalance}"/>
                            </f:facet>
                            <h:outputText value="#{item.cashBalance}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerAccountEntityTitle_creditTerm}"/>
                            </f:facet>
                            <h:outputText value="#{item.creditTerm.isDefaultTerm}"/>
                        </p:column>                    

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerAccountEntityTitle_lastModifiedAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.lastModifiedAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" action="#{customerInvoiceEntityController.doNothing}" 
                                             update="@form:displayCreditTerm"
                                             oncomplete="creditTermDialog.show()">
                                <f:setPropertyActionListener value="#{item.creditTerm}"  
                                                             target="#{creditTermEntityController.current}" /> 
                            </p:commandButton>
                        </p:column>

                        <p:column >  
                            <p:menuButton value="Options">       
                                <p:menuitem value=" Edit" ajax="false" icon="ui-icon ui-icon-disk" 
                                            action="Edit" >
                                    <f:setPropertyActionListener value="#{item.creditTerm}"  
                                                                 target="#{creditTermEntityController.current}" />
                                    <f:setPropertyActionListener value="#{creditTermEntityController.deepCloneOfCurrentCreditTerm}"  
                                                                 target="#{creditTermEntityController.oldCreditTerm}" />
                                </p:menuitem>
                                <p:menuitem value=" Delete" ajax="false" icon="ui-icon ui-icon-close"
                                            action="#{creditTermEntityController.performDestroy}">
                                    <f:setPropertyActionListener value="#{item.creditTerm}"  
                                                                 target="#{creditTermEntityController.current}" />
                                </p:menuitem>        
                            </p:menuButton>    
                        </p:column>

                    </p:dataTable>
                </h:panelGroup>

                <p:dialog header="Credit Term Detail" widgetVar="creditTermDialog" resizable="false"  
                          width="325" showEffect="explode" hideEffect="explode">    
                    <h:panelGrid columns="2" id="displayCreditTerm">
                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_creditLimit}"/>
                        <h:outputText value="#{creditTermEntityController.selected.creditLimit}" title="#{bundle.ViewCreditTermEntityTitle_creditLimit}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_discount}"/>
                        <h:outputText value="#{creditTermEntityController.selected.discount}" title="#{bundle.ViewCreditTermEntityTitle_discount}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_discountRepayTime}"/>
                        <h:outputText value="#{creditTermEntityController.selected.discountRepayTime}" title="#{bundle.ViewCreditTermEntityTitle_discountRepayTime}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_lateCharges}"/>
                        <h:outputText value="#{creditTermEntityController.selected.lateCharges}" title="#{bundle.ViewCreditTermEntityTitle_lateCharges}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_maxRepayTime}"/>
                        <h:outputText value="#{creditTermEntityController.selected.maxRepayTime}" title="#{bundle.ViewCreditTermEntityTitle_maxRepayTime}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_createdBy}"/>
                        <h:outputText value="#{creditTermEntityController.selected.createdBy.fullname}" title="#{bundle.ViewCreditTermEntityTitle_createdBy}"/>

                        <h:outputText value="#{bundle.ViewCreditTermEntityLabel_lastModifiedBy}"/>
                        <h:outputText value="#{creditTermEntityController.selected.lastModifiedBy.fullname}" title="#{bundle.ViewCreditTermEntityTitle_lastModifiedBy}"/>
                    </h:panelGrid>
                </p:dialog> 

            </h:form>
        </ui:define>
    </ui:composition>

</html>
